package com.edu.order.config;
 
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
 
/**
 * @ClassName RabbitmqConfig
 * @Description TODO
 * @Author
 * @Date
 * @Version 1.0
 */
@Configuration
public class RabbitmqConfig {
    //通知队列  交换机名称
    public static final String QUEUE_INFORM_WECHAT_PAY = "queue_inform_wechat_pay";
    public static final String EXCHANGE_DIRECT_INFORM="exchange_direct_inform";
    public static final String ROUTINGKEY_PAYMENT_SUCCESS="inform.#.success.#";

    //声明交换机
    @Bean(EXCHANGE_DIRECT_INFORM)
    public Exchange EXCHANGE_TOPICS_INFORM(){
        //durable(true) 持久化，mq重启之后交换机还在
        return ExchangeBuilder.directExchange(EXCHANGE_DIRECT_INFORM).durable(true).build();
    }
 
    //声明QUEUE_INFORM_WECHAT_PAY队列
    @Bean(QUEUE_INFORM_WECHAT_PAY)
    public Queue QUEUE_INFORM_EMAIL(){
        return new Queue(QUEUE_INFORM_WECHAT_PAY);
    }
    //ROUTINGKEY_PAYMENT_SUCCESS 队列绑定交换机，指定routingKey
    @Bean
    public Binding BINDING_QUEUE_INFORM_PAYMENT_SUCCESS(@Qualifier(QUEUE_INFORM_WECHAT_PAY) Queue queue,
                                              @Qualifier(EXCHANGE_DIRECT_INFORM) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_PAYMENT_SUCCESS).noargs();
    }
 
}